package com.conan.mvc.controller;

import com.conan.mvc.bean.User;
import org.springframework.http.HttpHeaders;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * @version 加油！！！
 * @Description
 * @Author 谷藤新一GYC
 * @Date 2022/10/26 - 10:57
 */
@Controller
public class HttpController {

    @RequestMapping("/testRequestBody")
    public String testRequestBody(@RequestBody String requestBody) throws UnsupportedEncodingException {
        requestBody= URLDecoder.decode(requestBody,"UTF-8");
        System.out.println(requestBody);
        return "success";
    }
    @RequestMapping("/testRequestEntity")
    public String testRequestEntity(RequestEntity<String> requestEntity) throws UnsupportedEncodingException {
        HttpHeaders headers = requestEntity.getHeaders();
        System.out.println("请求头："+headers);

        System.out.println("请求体："+URLDecoder.decode(requestEntity.getBody(),"UTF-8"));
        return "success";
    }

    @RequestMapping("/testResponse")
    public String testResponse(HttpServletResponse response) throws IOException {
        response.getWriter().print("hello,response");
        return null;
    }
    @RequestMapping("/testResponseBody")
    @ResponseBody
    public String testResponseBody(){
        return "success";
    }
    @RequestMapping("/testResponseUser")
    @ResponseBody
    public User testResponseUser(){
        return new User(1,"admin","213123",23,"男");
    }
    @RequestMapping("/testAxios")
    @ResponseBody
    public String testAxios(String username,String password){
        System.out.println(username);
        System.out.println(password);
        return null;
    }

}
   